package com.neusoft.tijian.service.impl;

import com.neusoft.tijian.mapper.DoctorMapper;
import com.neusoft.tijian.po.Doctor;
import com.neusoft.tijian.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 医生服务实现类
 */
@Service
public class DoctorServiceImpl implements DoctorService {

    @Autowired
    private DoctorMapper doctorMapper;

    /**
     * 医生登录验证
     * @param docCode 医生编码
     * @param password 登录密码
     * @return 验证通过返回医生信息，否则返回null
     */
    @Override
    public Doctor login(String docCode, String password) {
        // 1. 打印日志，跟踪登录过程
        System.out.println("医生登录验证 - docCode: " + docCode + ", password: " + password);

        // 2. 根据医生编码查询数据库
        Doctor doctor = doctorMapper.selectByDocCode(docCode);
        if (doctor == null) {
            System.out.println("登录失败: 未找到医生编码为 " + docCode + " 的记录");
            return null;
        }

        // 3. 验证密码（数据库存储的密码与输入密码直接比对）
        if (!doctor.getPassword().equals(password)) {
            System.out.println("登录失败: 密码不匹配 - 输入密码: " + password +
                    ", 数据库密码: " + doctor.getPassword());
            return null;
        }

        // 4. 登录成功，返回医生信息（实际项目中可清除密码信息）
        System.out.println("登录成功: 医生 " + doctor.getRealName() + " (编码: " + docCode + ")");
        return doctor;
    }
}
